package cn.lyq.card.ui.phone

import android.os.Bundle
import android.view.View
import cn.lyq.card.R
import cn.lyq.card.base.BaseDialogFg
import cn.lyq.card.utils.setClick
import com.blankj.utilcode.util.ClipboardUtils
import com.blankj.utilcode.util.PhoneUtils
import com.blankj.utilcode.util.ToastUtils
import kotlinx.android.synthetic.main.dialog_customer_service_phone.tvConfirm
import kotlinx.android.synthetic.main.dialog_phone_call.*


class PhoneCallFg(override val rootId: Int = R.layout.dialog_phone_call) : BaseDialogFg() {

    companion object {
        private const val KEY_PHONE = "PHONE"

        fun newInstance(phone: String): PhoneCallFg {
            val args = Bundle()
            args.putString(KEY_PHONE, phone)
            val fragment = PhoneCallFg()
            fragment.arguments = args
            return fragment
        }
    }

    private val phone by lazy {
        arguments?.getString(KEY_PHONE, "") ?: ""
    }

    override fun initView(view: View) {
        super.initView(view)
        tvPhone.text = "【${phone}】"
    }

    override fun initListener(view: View) {
        super.initListener(view)
        tvConfirm.setClick {
            PhoneUtils.dial(phone)
            dismiss()
        }
        tvPhone.setClick {
            ClipboardUtils.copyText(phone)
            ToastUtils.showShort(getString(R.string.str_copy_success))
        }
        tvCancel.setClick {
            dismiss()
        }
    }

}